package com.example.yingjiguanli_demo.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.yingjiguanli_demo.pojo.UserAnswers;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author scj
 * @since 2024-11-04
 */
@Mapper
public interface UserAnswersMapper extends BaseMapper<UserAnswers> {
    @Insert("INSERT INTO user_answers (user_id, question_id, user_answer, is_correct, answered_at) " +
            "VALUES (#{userId}, #{questionId}, #{userAnswer}, #{isCorrect}, #{answeredAt})")
    void userAnswersInsert(UserAnswers userAnswer);

    @Select("SELECT COUNT(*) FROM user_answers WHERE user_id = #{userId} AND is_correct = TRUE")
    int getCorrectAnswerCountByUser(@Param("userId") int userId);
}
